//
//  MySetController.m
//  PosApp
//
//  Created by 李英新 on 2018/10/3.
//  Copyright © 2018年 李英新. All rights reserved.
//

#import "MySetController.h"
#import "ChangeMyNewsController.h"

#import "PayBDController.h"
#import "AddMyNewsController.h"
#import "MyAddressController.h"
#import "MainNavigationController.h"
#import "LoginViewController.h"

@interface MySetController ()
@property (weak, nonatomic) IBOutlet UIView *TopView;
@property (weak, nonatomic) IBOutlet UIView *BackView;
@property (weak, nonatomic) IBOutlet UILabel *SizeLabel;
@property (weak, nonatomic) IBOutlet UILabel *BoundLabel;

@end

@implementation MySetController

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    [self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    
    [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:nil];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    self.navigationItem.title = @"设置";
    CAGradientLayer *gl = [CAGradientLayer layer];
    gl.frame = CGRectMake(0,0,KScreenW,self.TopView.bounds.size.height);
    gl.startPoint = CGPointMake(0, 0);
    gl.endPoint = CGPointMake(1, 1);
    gl.colors = @[(__bridge id)[UIColor colorWithRed:251/255.0 green:40/255.0 blue:68/255.0 alpha:1].CGColor,(__bridge id)[UIColor colorWithRed:246/255.0 green:87/255.0 blue:43/255.0 alpha:1].CGColor];
    gl.locations = @[@(0.0),@(1.0f)];
    self.TopView.layer.masksToBounds = YES;
    [self.TopView.layer addSublayer:gl];
    
    self.BackView.layer.cornerRadius = 8;
    self.BackView.layer.masksToBounds = YES;
    
    float cacheSize = [MainObjectWay FileSize];
    self.SizeLabel.text = [NSString stringWithFormat:@"%.2fMB",cacheSize];
    
    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
    NSString *app_Name = [infoDictionary objectForKey:@"CFBundleDisplayName"];// app名称
    NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];// app版本
    NSString *app_build = [infoDictionary objectForKey:@"CFBundleVersion"]; // app build版本
    NSLog(@"app名称 %@ app版本 %@ app build版本 %@",app_Name,app_Version,app_build);
    self.BoundLabel.text = [NSString stringWithFormat:@"%@.%@",app_Version,app_build];
    
}
- (IBAction)ClickOnBtnOfSetController01:(id)sender {
    //修改资料
    ChangeMyNewsController * changeC = [[ChangeMyNewsController alloc] init];
    [self.navigationController pushViewController:changeC animated:YES];
    
}
- (IBAction)ClickOnBtnOfSetController02:(id)sender {
    //支付宝绑定
    PayBDController * PayC = [[PayBDController alloc] init];
    [self.navigationController pushViewController:PayC animated:YES];
    
}
- (IBAction)ClickOnBtnOfSetController03:(id)sender {
    //信息补全
    AddMyNewsController * addNews = [[AddMyNewsController alloc] init];
    [self.navigationController pushViewController:addNews animated:YES];
}
- (IBAction)ClickOnBtnOfSetController04:(id)sender {
    //地址管理
    MyAddressController * AddressC = [[MyAddressController alloc] init];
    [self.navigationController pushViewController:AddressC animated:YES];
    
}
- (IBAction)ClickOnBtnOfSetController05:(id)sender {
    
    //清理缓存
    UIAlertController * alertC = [UIAlertController alertControllerWithTitle:@"提示" message:@"您确定要清除本地缓存" preferredStyle:UIAlertControllerStyleAlert];
    //
    [alertC addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [MainObjectWay RemoveFileSize];
        //读取缓存大小
        float cacheSize = [MainObjectWay FileSize] ;
        self.SizeLabel.text = [NSString stringWithFormat:@"%.2fMB",cacheSize];
    }]];
    
    [alertC addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];
    [self presentViewController:alertC animated:YES completion:nil];
}
- (IBAction)ClickOnBtnOfSetController06:(id)sender {
    //退出账号
    SetKLogin(NO);
    UIApplication *app = [UIApplication sharedApplication];
    AppDelegate *dele = (AppDelegate*)app.delegate;
//    dele.window.rootViewController = [[LoginViewController alloc] init];
    LoginViewController * loginC = [[LoginViewController alloc] init];
    MainNavigationController * nac = [[MainNavigationController alloc] initWithRootViewController:loginC];
    dele.window.rootViewController = nac;
    
    
    
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
